package com.shengsiyuan.nio;

import java.io.FileInputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class NioTest02 {

    public static void main(String[] arg) throws Exception {

        FileInputStream fileInputStream = new FileInputStream("C:\\Users\\Administrator\\IdeaProjects\\Netty-Learning\\src\\main\\java\\com\\shengsiyuan\\nio\\text\\Niotest.txt");
        FileChannel fileChannel = fileInputStream.getChannel();

        ByteBuffer byteBuf = ByteBuffer.allocate(512);
        // 读取文件内容到 ByteBuffer
        fileChannel.read(byteBuf);

        byteBuf.flip();

        while (byteBuf.hasRemaining()) {
            System.out.print((char) byteBuf.get());
        }

        fileInputStream.close();
    }
}
